package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;



public class DBUtil {
	private String dbUrl = "jdbc:mysql://localhost:3306/studentmanagement?useSSL=false";
	private String dbUserName = "root";
	private String dbPassword = "123456";
	private String dbname = "com.mysql.cj.jdbc.Driver";
 	private static Connection con = null;
//	private static PreparedStatement pstmt = null;
//	private static  ResultSet  res=null;
	
	public Connection getCon() {
		try {
			Class.forName(dbname);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		try {
			con = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return con;
	}
	
	public void closeCon(Connection con) throws Exception{
		if(con != null) {
			con.close();
		}
	}
	
	public static void main(String[] args) {
		DBUtil dbutil = new DBUtil();		
		Connection con=	dbutil.getCon();
        System.out.println(con);

	}

	

}
